const jsonBodyTs: string = `
async function jsonBody() {
  // 请求参数
  const request: DemoRequest = {
    id: 1001,
    name: 'zhangsan',
    man: false,
    createTime: new Date(),
  };

  // 发起请求: await 同步等待响应结果, 参数为 json 对象
  let respData = await demo.jsonBody(request);
  // 处理响应结果
  respRef.value = respData;

}
`;

const jsonBodyJava: string = `
@PostMapping("/jsonBody")
public BaseResponse<Long> jsonBody(@Valid @RequestBody DemoRequest request) {
  return BaseResponse.success(request.getId());
}
`;

const jsonPathTs: string = `
async function jsonPath() {
  const id: number = 1001;

  // 发起请求: await 同步等待响应结果, 参数为 json 对象
  let respData = await demo.jsonPath(id);
  // 处理响应结果
  respRef.value = respData;

}
`;
const jsonPathJava: string = `
@DeleteMapping("/jsonPath/{id}")
public BaseResponse<Boolean> jsonPath(@PathVariable Long id) {
  return BaseResponse.success(true);
}
`;

const jsonBodyAndPathTs: string = `
async function jsonBodyAndPath() {
  const id: number = 1001;
  // 请求参数
  const request: DemoRequest = {
    id: 1001,
    name: 'zhangsan',
    man: false,
    createTime: new Date(),
  };

  // 发起请求: await 同步等待响应结果, 参数为 json 对象
  let respData = await demo.jsonBodyAndPath(id, request);
  // 处理响应结果
  respRef.value = respData;
}
`;

const jsonBodyAndPathJava: string = `
@PutMapping("/jsonBodyAndPath/{id}")
public BaseResponse<String> jsonBodyAndPath(@PathVariable Long id, @Valid @RequestBody DemoRequest request) {
  return BaseResponse.success(request.toString());
}
`;

const jsonBasicListTs: string = `
async function jsonBasicList() {
  const list: number[] = [1001, 1002, 1003];

  // 发起请求: await 同步等待响应结果, 参数为 list 对象，不需要 {} 包裹
  let respData = await demo.jsonBasicList(list);
  // 处理响应结果
  respRef.value = respData;

}
`;

const jsonBasicListJava: string = `
@PostMapping("/jsonBasicList")
public BaseResponse<String> jsonBasicList(@RequestBody List<Long> ids) {
  return BaseResponse.success(ids.toString());
}
`;

const formBasicTs: string = `
async function formBasicTs() {
  // 请求参数
  const name: string = 'hello';
  // 发起请求: await 同步等待响应结果, 参数为 json 对象
  let respData = await demo.formBasic({ name });
  // 处理响应结果
  respRef.value = respData;

}
`;

const formBasicJava: string = `
@PostMapping("/formBasic")
public BaseResponse<DemoDO> formBasic(String name) {
    return BaseResponse.success(getDemoList().get(0));
}
`;

const jsonObjectListTs: string = `
async function jsonObjectList() {
  // prettier-ignore
  const demos: DemoRequest[] = [
    {  id: 1001, name: 'zhangsan', man: false, createTime: new Date(), },
    {  id: 1002, name: 'lisi', man: false, createTime: new Date(), }
  ];

  // 发起请求: await 同步等待响应结果, 参数为 json 对象
  let respData = await demo.jsonObjectList(demos);
  // 处理响应结果
  respRef.value = respData;

}
`;

const jsonObjectListJava: string = `
@PostMapping("/jsonObjectList")
public BaseResponse<List<Long>> jsonObjectList(@RequestBody List<DemoRequest> requests) {
    List<Long> idList = requests.stream().map(DemoRequest::getId).collect(Collectors.toList());
    return BaseResponse.success(idList);
}
`;

const jsonNoBodyTs: string = `
async function jsonNoBody() {
  // 发起请求: await 同步等待响应结果
  let respData = await demo.jsonNoBody();
  // 处理响应结果
  respRef.value = respData;
}
`;

const jsonNoBodyJava: string = `
@Operation(summary = "json协议: 无参", description = "响应类型: List自定义类型")
@PostMapping("/jsonNoBody")
public BaseResponse<List<DemoDO>> jsonNoBody() {
    return BaseResponse.success(getDemoList());
}
`;

const jsonPagerTs: string = `
async function jsonPager() {
  // prettier-ignore
  const query: DemoQuery = {
    name:'zhangsan',
    page: 1,
    pageSize:10
  }

  // 发起请求: await 同步等待响应结果, 参数为 json 对象
  let respData = await demo.jsonPager(query);
  // 处理响应结果
  respRef.value = respData;
}
`;

const jsonPagerJava: string = `
@PostMapping("/jsonPager")
public BaseResponse<BasePager<DemoDO>> jsonPager(@RequestBody DemoQuery request) {
    BasePager<DemoDO> pager = new BasePager<>();
    pager.setPages(10);
    pager.setTotal(100);
    pager.setItems(getDemoList());
    pager.getItems().forEach(item -> item.setName(request.getName() + "-" + item.getName()));
    return BaseResponse.success(pager);
}
`;
const formMultiBasicTs: string = `
async function formMultiBasic() {
  // 请求参数
  const name: string = 'hello';
  const id: number = 1001;
  // 发起请求: await 同步等待响应结果, 参数为 json 对象
  let respData = await demo.formMultiBasic({ id, name });
  // 处理响应结果
  respRef.value = respData;
}
`;

const formMultiBasicJava: string = `
@PostMapping("/formMultiBasic")
public BaseResponse<DemoDO> formMultiBasic(String name, Long id) {
    DemoDO demoDO = getDemoList().get(0);
    demoDO.setName(name);
    demoDO.setId(id);
    return BaseResponse.success(demoDO);
}
`;

const formObjectJava: string = `
@PostMapping("/formObject")
public BaseResponse<List<DemoTreeDO>> formObject(DemoQuery request) {
    List<DemoTreeDO> treeList = new ArrayList<>();
    for (DemoDO demoDO : getDemoList()) {
        DemoTreeDO demoTreeDO = BeanUtils.copyProperties(demoDO, DemoTreeDO.class);
        demoTreeDO.setName(request.getName());
        demoTreeDO.setChildren(BeanUtils.copyToList(getDemoList(5), DemoTreeDO.class));
    }
    return BaseResponse.success(treeList);
}
`;

const formObjectTs: string = `
async function formObject() {
  // prettier-ignore
  const query: DemoQuery = {
    name:'zhangsan',
    page: 1,
    pageSize:10
  }

  // 发起请求: await 同步等待响应结果, 参数为 json 对象
  let respData = await demo.formObject(query);
  // 处理响应结果
  respRef.value = respData;
}
`;

// prettier-ignore
export default {
  jsonBodyJava, jsonBodyTs,
  formBasicJava, formBasicTs,
  jsonPathJava, jsonPathTs,
  jsonBodyAndPathJava, jsonBodyAndPathTs,
  jsonBasicListJava, jsonBasicListTs, 
  jsonObjectListJava, jsonObjectListTs,
  jsonPagerJava, jsonPagerTs,
  jsonNoBodyJava, jsonNoBodyTs,
  formMultiBasicJava, formMultiBasicTs,
  formObjectJava, formObjectTs,
};
